import api from '@/api';
import {GET_IMAGE_LIST,GET_CATEGORY,CHANGE_SWIPER,INIT_CATEGORY,CHANGE_INDEX} from '../actionTypes';

export const getImageList = (params) => {
    return (dispatch) => {
        //请求图片列表
        api.getImageList(params).then(res => {
            if(res.code === 1){
                //派发action
                dispatch({
                    type:GET_IMAGE_LIST,
                    list:res.data
                })
            }
        })
    }
}

// 获取对应分类的图片

export const getCategory = (params) => {
    return (dispatch) => {
        //请求图片列表
        api.getCategory(params).then(res => {
            if(res.code === 1){
                // //派发action
                dispatch({
                    type:GET_CATEGORY,
                    data:res.data
                })
            }
        })
    }
}

//修改swiper弹窗的显示和隐藏
export const changeSwiper = (isOpen) => {
    return {
        type:CHANGE_SWIPER,
        isOpen
    }
}

//初始化图片分类数据
export const initCategory = () => {
    return {
        type:INIT_CATEGORY
    }
}

//初始化swiper展示的数据

export const changeIndex = (index) => {
    return {
        type:CHANGE_INDEX,
        index
    }
}